<template>
  <!-- 小说首页 -->
  <div class="home">
    <div class="search">
      <input type="text" v-model="words" placeholder="输入你想看的书名..." @keydown.enter="search">
      <button @click="search" >查找</button>
    </div>
    <div class="novel">
      <div class="book" v-for="(novel, index) in novelList" :key="index">
        <!-- query传参 -->
        <router-link :to="{
          path:'/deltails',
          query:{
            fictionId:novel.fictionId
          }
        }">
          <div class="img">
            <img :src="novel.cover" alt="" class="cover">
          </div>
          <div class="info">
            <div class="title">
              <h3>{{novel.title}}</h3>
            </div>
            <div class="author">{{novel.author}} · 著</div>
            <div class="fictionType">
              <div class="border">
                {{novel.fictionType}}
              </div>
            </div>
            <div>
              <div class="descs">{{novel.descs}}</div>
            </div>
            <div class="uptime">最近更新：{{novel.updateTime}}</div>
          </div>
        </router-link>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'HomeView',
  data () {
    return {
      novelList: '',
      words: ''
    }
  },
  methods: {
    search () {
      // console.log(this.words)
      this.$http.request({
        url: 'http://api.pingcc.cn/fiction/search/title/' + this.words + '/1/12',
        method: 'get'
      })
        .then((res) => {
          console.log(res.data.data)
          this.novelList = res.data.data
        })
        .catch((err) => {
          console.log(err)
        })
    },
    getData () {
      this.$http.request({
        url: 'http://api.pingcc.cn/fiction/search/title/斗罗/1/11',
        method: 'get'
      })
        .then((res) => {
          console.log(res.data.data)
          this.novelList = res.data.data
        })
        .catch((err) => {
          console.log(err)
        })
    }
  },
  created () {
    this.getData()
  }
}
</script>

<style scoped>
.search{
  width: 70%;
  margin: 0 auto 50px;
  text-align: center;
  height: 50px;
  line-height: 50px;
}
.search>input{
  border: 2px solid #ababab;
  border-radius: 5px 0 0 5px;
  padding: 0 8px;
  height: 40px;
  width: 250px;
}
.search>button{
  height: 44px;
  border-radius:0 5px 5px 0;
  background-color: #fd5f51;
  border: none;
  width: 80px;
  color: #FFFFFF;
  font-size: 15px;
}
.novel{
  display: flex;
  width: 1200px;
  margin: 0 auto;
  flex-wrap: wrap;
  /*justify-content: center;*/
}
.book{
  /* display: flex; */
  width: 25%;
  margin-top: 20px;
  padding: 10px 0;
  text-align: center;
  border-bottom: 2px solid #d8d8d8;
}
.info{
  /* display: flex;
  flex-direction: column; */
  /* width: 800px; */
  padding: 10px 15px;
}
.info>div{
  margin: 15px 0;
}
.img{
  width: 100%;
  padding-top: 10px;
  /*height: 40%;*/
}
.cover{
  width: 210px;
  height: 280px;
  /*margin: 10px auto;*/
  flex-shrink:0
}
.title{
  color: #252525;
  font-size: 22px;
}
.title:hover{
  color: #ee6346;
}
.author{
  font-size: 15px;
  color: #3d3d3d;
}
.descs{
  width: 80%;
  height: 200px;
  margin: 0 auto;
  text-align: left;
  color: #9d9d9d;
  font-size: 17px;
  overflow: hidden;
}
.border{
  width: 100px;
  height: 28px;
  line-height: 28px;
  border-radius: 20px;
  margin: 0 auto;
  font-size: 13px;
  border: 1px solid #3589f5;
  color: #3589f5;
}
.uptime{
  color: #9dc7f5;
  font-size: 13px;
}
</style>
